<?php
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
?>
<div class="span10">
    <h1 class="page-header">Cập nhật thông tin</h1>
    <?php if (Yii::app()->user->hasFlash('error')): ?>
        <div class="alert alert-error fade in">
            <button data-dismiss="alert" class="close" type="button">×</button>
            <?php echo Yii::app()->user->getFlash('error') ?>
        </div>
    <?php endif; ?>
    <?php if (Yii::app()->user->hasFlash('success')): ?>
        <div class="alert alert-success fade in">
            <button data-dismiss="alert" class="close" type="button">×</button>
            <?php echo Yii::app()->user->getFlash('success') ?>
        </div>
    <?php endif; ?>
    <form enctype=""></form>
    <?php
    $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
        'type' => 'vertical',
        'id' => 'form-thongbaomoithau',
        'enableAjaxValidation' => false,
        'htmlOptions' => array('enctype' => 'multipart/form-data'),
    ));
    ?>
    <div id="group-tenduan" class="control-group">
        <label class="control-label">Tên gói thầu</label>
        <div class="controls">
            <?php echo $form->textField($model, 'tenGoiThau', array('class' => 'span12')) ?>
            <?php echo $form->error($model, 'tenGoiThau', array('class' => 'error-message')); ?>
        </div>
    </div>
    <div id="group-tengoithau" class="control-group">
        <label class="control-label">Ngành</label>
        <div class="controls">
            <?php echo $form->dropDownList($model, 'nganh', CHtml::listData(DanhSachNganh::model()->findAll(), 'value', 'value'), array('class' => 'span12')) ?>
            <?php echo $form->error($model, 'nganh', array('class' => 'error-message')); ?>
        </div>
    </div>
    <div id="group-nguonvon" class="control-group">
        <label class="control-label">Lĩnh vực</label>
        <div class="controls">
            <?php echo $form->dropDownList($model, 'linhVuc', CHtml::listData(DanhSachLinhVuc::model()->findAll(), 'value', 'value'), array('class' => 'span12')) ?>
            <?php echo $form->error($model, 'linhVuc', array('class' => 'error-message')); ?>
        </div>
    </div>
    <div id="group-benmoithau" class="control-group">
        <label class="control-label">Địa điểm</label>
        <div class="controls">
            <?php echo $form->dropDownList($model, 'diaDiem', CHtml::listData(DiaDiem::model()->findAll(), 'value', 'value'), array('class' => 'span12')) ?>
            <?php echo $form->error($model, 'diaDiem', array('class' => 'error-message')); ?>
        </div>
    </div>
    <div id="group-hinhthucdauthau" class="control-group">
        <label class="control-label">Tên dự án</label>
        <div class="controls">
            <?php echo $form->textArea($model, 'tenDuAn', array('class' => 'span12')) ?>
            <?php echo $form->error($model, 'tenDuAn', array('class' => 'error-message')); ?>
        </div>
    </div>
    <div id="group-phuongthucdauthau" class="control-group">
        <label class="control-label">Nguồn vốn</label>
        <br>
        <div class="controls">
            <?php echo $form->radioButtonList($model, 'nguonVon', array('Không xác định' => 'Không xác định', 'Trong nước' => 'Trong nước', 'Nước ngoài' => 'Nước ngoài'), array('labelOptions' => array('style' => 'display:inline'), 'separator' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;')) ?>
            <?php echo $form->error($model, 'nguonVon', array('class' => 'error-message')); ?>
        </div>
    </div>
    <div id="group-hinhthuchopdong" class="control-group">
        <label class="control-label">Bên mời thầu</label>
        <div class="controls">
            <?php echo $form->textArea($model, 'benMoiThau', array('class' => 'span12')) ?>
            <?php echo $form->error($model, 'benMoiThau', array('class' => 'error-message')); ?>
        </div>
    </div>
    <div id="group-diadiem" class="control-group">
        <label class="control-label">Hình thức đấu thầu</label>
        <div class="controls">
            <?php echo $form->dropDownList($model, 'hinhThuc', CHtml::listData(HinhThucDauThau::model()->findAll(), 'value', 'value'), array('class' => 'span12')) ?>
            <?php echo $form->error($model, 'hinhThuc', array('class' => 'error-message')); ?>
        </div>
    </div>
    <div id="group-thoigianthuchien" class="control-group">
        <label class="control-label">Thời gian bắt đầu bán HSMT</label>
        <div class="controls">
            <?php
            Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
            $this->widget('CJuiDateTimePicker', array(
                'model' => $model,
                'attribute' => 'batDau',
                'language' => '',
                'htmlOptions' => array(
                    'class' => 'span12'
                ),
                    )
            );
            ?>
            <?php echo $form->error($model, 'batDau', array('class' => 'error-message')); ?>
        </div>
    </div>
    <div id="group-nhathautrungthau" class="control-group">
        <label class="control-label">Thời gian kết thúc bán HSMT</label>
        <div class="controls">
            <?php
            Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
            $this->widget('CJuiDateTimePicker', array(
                'model' => $model,
                'attribute' => 'ketThuc',
                'language' => '',
                'htmlOptions' => array(
                    'class' => 'span12'
                ),
                    )
            );
            ?>
            <?php echo $form->error($model, 'ketThuc', array('class' => 'error-message')); ?>
        </div>
    </div>
    <div id="group-giagoithau" class="control-group">
        <label class="control-label">Địa điểm bán</label>
        <div class="controls">
            <?php echo $form->textArea($model, 'diaDiemBan', array('class' => 'span12')) ?>
            <?php echo $form->error($model, 'diaDiemBan', array('class' => 'error-message')); ?>
        </div>
    </div>
    <div id="group-giatrungthau" class="control-group">
        <label class="control-label">Giá bán</label>
        <div class="controls">
            <?php echo $form->textField($model, 'giaBan', array('class' => 'span12')) ?>
            <?php echo $form->error($model, 'giaBan', array('class' => 'error-message')); ?>
        </div>
    </div>
    <div id="group-quyetdinh" class="control-group">
        <label class="control-label">Thời gian đóng thầu</label>
        <div class="controls">
            <?php
            Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
            $this->widget('CJuiDateTimePicker', array(
                'model' => $model,
                'attribute' => 'thoiGianDongThau',
                'language' => '',
                'htmlOptions' => array(
                    'class' => 'span12'
                ),
                    )
            );
            ?>
            <?php echo $form->error($model, 'thoiGianDongThau', array('class' => 'error-message')); ?>
        </div>
    </div>
    <div id="group-ngayxuatban" class="control-group">
        <label class="control-label" for="ngayxuatban">Ngày xuất bản</label>

        <div class="controls">
            <?php
            Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
            $this->widget('CJuiDateTimePicker', array(
                'model' => $model,
                'attribute' => 'ngayXuatBan',
                'language' => '',
                'mode' => 'date',
                'htmlOptions' => array(
                    'class' => 'span12'
                ),
                    )
            );
            ?>
            <?php echo $form->error($model, 'ngayXuatBan', array('class' => 'error-message')); ?>
        </div>
    </div>
    <div id="group-sobaodang" class="control-group">
        <label class="control-label" for="sobaodang">Số báo đăng</label>

        <div class="controls">
            <?php echo $form->textField($model, 'soBaoDang', array('id' => 'sobaodang', 'class' => 'span12')) ?>
            <?php echo $form->error($model, 'soBaoDang', array('class' => 'error-message')); ?>
        </div>
    </div>
    <div id="group-tinhtrang" class="control-group">
        <label class="control-label" for="tinhtrang">Tình trạng thông tin</label>

        <div class="controls">
            <?php echo $form->textArea($model, 'tinhTrang', array('id' => 'tinhtrang', 'class' => 'span12')) ?>
            <?php echo $form->error($model, 'tinhTrang', array('class' => 'error-message')); ?>
        </div>
    </div>
    <div id="group-mathongtin" class="control-group">
        <label class="control-label" for="mathongtin">Mã thông tin</label>

        <div class="controls">
            <?php echo $form->textField($model, 'maThongTin', array('id' => 'mathongtin', 'class' => 'span12')) ?>
            <?php echo $form->error($model, 'maThongTin', array('class' => 'error-message')); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">Duyệt tin</label>

        <div class="controls">
            <?php echo $form->dropDownList($model, 'is_checked', array(FormData::CHECKED => 'Được duyệt', FormData::NOT_CHECKED => 'Không được duyệt', FormData::PENDING_CHECKED => 'Chờ duyệt'), array('id' => 'isChecked', 'class' => 'span5')) ?>
            <?php echo $form->error($model, 'is_checked', array('class' => 'error-message')); ?>
        </div>
    </div>
    <div id="group-image" class="control-group">
        <label class="control-label">Ảnh</label>

        <div class="controls">
            <?php echo $form->fileField($model, 'image_url', array('id' => 'imageUrl', 'class' => 'span12')) ?>
            <image style="display: <?php echo $model->image_url !== null ? '' : 'none' ?>" width="100px" src="<?php echo Yii::app()->getBaseUrl(true) . $model->image_url; ?>" />
            <div style="display: none" id="error-image" class="error-message">(*) Ảnh là bắt buộc.</div>
        </div>
    </div>
    <div id="group-cause" class="control-group">
        <label class="control-label">Lý do</label>

        <div class="controls">
            <?php echo $form->textArea($model, 'cause', array('id' => 'cause', 'class' => 'span12')) ?>
            <div style="display: none" id="error-cause" class="error-message">(*) Lý do là bắt buộc.</div>
        </div>
    </div>
    <div class="form-actions">
        <button type="button" id="save-thongbaomoithau" class="btn btn-primary">Lưu</button>
        <a id="all-user" href="<?php echo $this->createUrl('user/index') ?>" class="btn btn-default">Quay lại danh sách</a>
    </div>
    <?php $this->endWidget(); ?>
</div>
<script type="text/javascript">
    $(document).ready(function() {
        var status = $('#isChecked').val();
        switch (status) {
            case '1':
                $('#group-image').show();
                $('#group-cause').hide();
                break;
            case '2':
                $('#group-image').hide();
                $('#group-cause').show();
                break;
            default:
                $('#group-image').hide();
                $('#group-cause').hide();
                break;
        }
    });
    $('#isChecked').change(function() {
        var status = $('#isChecked').val();
        switch (status) {
            case '1':
                $('#group-image').show();
                $('#group-cause').hide();
                break;
            case '2':
                $('#group-image').hide();
                $('#group-cause').show();
                break;
            default:
                $('#group-image').hide();
                $('#group-cause').hide();
                break;
        }
    });
    $('#save-thongbaomoithau').click(function() {
        var status = $('#isChecked').val();
        switch (status) {
            case '1':
<?php if ($model->image_url !== null || $model->image_url !== ''): ?>
                    $('#form-thongbaomoithau').submit();
<?php else: ?>
                    var image = $('#imageUrl').val();
                    if (image !== null && image !== '') {
                        $('#form-thongbaomoithau').submit();
                    } else {
                        $('#error-image').show();
                    }
<?php endif; ?>
                break;
            case '2':
                var cause = $('#cause').val();
                if (cause !== null && cause !== '') {
                    $('#form-thongbaomoithau').submit();
                } else {
                    $('#error-cause').show();
                }
                break;
            default:
                $('#form-thongbaomoithau').submit();
                break;
        }
    });
</script>
